package com.yidu.BusinessParameters.controller;

import com.yidu.BusinessParameters.entity.MarketEntity;
import com.yidu.BusinessParameters.service.MarketService;
import com.yidu.Util.util.Dbutil;
import com.yidu.Util.util.TableIdUtil;
import com.yidu.Util.util.TableNameUtil;
import com.yidu.Util.util.TableTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class MarketController {

    @Autowired
    private MarketService marketService;
    @Autowired
    Dbutil dbutil;

    @RequestMapping("/marketSelect")
    public Map marketSelect(){
        System.out.println("查询");
        List<MarketEntity> MarketEntitylist = marketService.marketSelect();
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",marketService.two());
        map.put("data",MarketEntitylist);
        return map;
    }

    @RequestMapping("/marketSelects")
    public Map marketSelects(int page, int limit,MarketEntity marketEntity){
        System.out.println("查询");
        List<MarketEntity> MarketEntitylists = marketService.marketSelects(page,limit,marketEntity);
        Map map=new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",marketService.two());
        map.put("data",MarketEntitylists);
        return map;
    }

    @RequestMapping("/marketinsert")
    public int marketinsert(MarketEntity marketEntity){
        String maxId = dbutil.getMaxId3(TableIdUtil.MID, TableNameUtil.M, TableTimeUtil.MTime,marketEntity.getInputDate());
        marketEntity.setMarketId(maxId);
        if (marketEntity.getFundId()==null){
            marketEntity.setFundId("000899");
        }
        int i = marketService.marketinsert(marketEntity);
        System.out.println(marketEntity);
        return i;
    }

    @RequestMapping("/marketdelete")
    public int marketdelete(String marketId){
        int i = marketService.marketdelete(marketId);
        return i;
    }

    @RequestMapping("/marketupdate")
    public int marketupdate(MarketEntity marketEntity){
        int i = marketService.marketupdate(marketEntity);
        return i;
    }
}
